﻿using System.Collections.Generic;
using CivilRegistry.ControlledModel.Repository;

namespace CivilRegistry.ControlledModel
{
    /// <summary>
    /// The district object.
    /// </summary>
    public partial class District
    {
        /// <summary>
        /// Holds the <see cref="DistrictRepository"/> instance.
        /// </summary>
        static DistrictRepository repository = new DistrictRepository();

        /// <summary>
        /// Finds the <see cref="District"/> by Id.
        /// </summary>
        /// <param name="id">The id of the <see cref="District"/>.</param>
        /// <returns>Found <see cref="District"/> object, null if not found.</returns>
        public static District FindById(int id)
        {
            return repository.FindBy(district => district.DistrictId == id);
        }

        /// <summary>
        /// Finds the <see cref="District"/> by name.
        /// </summary>
        /// <param name="name">The name of the district.</param>
        /// <returns>Found <see cref="District"/> object, null if not found.</returns>
        public static District FindByName(string name)
        {
            return repository.FindBy(district => district.DistrictName == name);
        }

        /// <summary>
        /// Finds all <see cref="District"/>s.
        /// </summary>
        /// <returns>Found <see cref="District"/> objects, empty if none are found.</returns>
        public static List<District> FindAll()
        {
            return repository.FindAll();
        }

        /// <summary>
        /// Finds <see cref="District"/>s by state id.
        /// </summary>
        /// <param name="stateId">The state id.</param>
        /// <returns>Found <see cref="District"/> objects, empty if none are found.</returns>
        public static List<District> FindAllByStateId(int stateId)
        {
            return repository.FindAll(district => district.State.StateId == stateId);
        }
    }
}